<?php
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";

$err=0;
//'****************************************
//' N I V E L    1
//'****************************************
$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
$strSql= "select * from PROVINCIA order by des";
$strid1 = SoloFun_ExecSqlFull($strSql, $arrProvincias, $oConexion);
//   'response.Write(ret)
if ($_REQUEST["CmbModulo"] != "") {
    $strid1=$_REQUEST["CmbModulo"];
}

//'****************************************
//' N I V E L    2
//'****************************************
$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
$strSql="select * from CANTON where id_provincia=" . $strid1;
$strSql .= " order by des";
$ret=SoloFun_ExecSqlFull ($strSql,$arrData, $oConexion);

$oConexion = new Conexion($MIES["motor_base"], $MIES["db_usuario"], $MIES["db_password"],
        $MIES["basedatos"], $MIES["servidor"], $MIES["flags"], $MIES["encoding"]);
$strSql="select (max(id)+1) as id  from CANTON";
$strSql .= " where id_provincia=" . $strid1;
$MaxId = SoloFun_ExecSqlFull ($strSql,$ArrMaxId, $oConexion);

if (is_null($MaxId))
    $MaxId = 1;

?>

<html>
    <head>
        <title>Documentacion</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT></head>

    <body topmargin=0 leftmargin=0>
        <!-- Include File="includes/trn_header.asp" -->
        <p align="center" class="SoloStyle_TituloPaginas">Tabla de Cantones/Ciudades</p>
        <form name="frmIngreso" action="trn_GrabaCanton.php" method="POST">
            <table border="0" width="50%" align="center">
                <tr>
                    <td class="SoloStyle_Etiqueta" ><strong>Provincia </strong></td>
                    <td ><select name="CmbModulo" class="SoloStyle_Texto" OnChange="document.frmIngreso.action='canton_ciudad.php';document.frmIngreso.submit();" style="width:185px">
                            <?php
                            for ($i=0; $i < count($arrProvincias);$i++) {
                                $ind=$arrProvincias[$i][0];
                                $jnd=$_REQUEST["CmbModulo"];
                                if ($jnd==$ind) {
                                    echo "<option value='" . $ind . "' SELECTED >" . $arrProvincias[$i][1] . "</option>";
                                }else {
                                    echo "<option value='" . $ind . "'>" . $arrProvincias[$i][1] . "</option>";
                                }
                            }
                            ?>
                        </select></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">C&oacute;digo</td>
                    <td><input name="hidId1" type="text" class="SoloStyle_Texto" value="<?php echo $MaxId; ?>" size="40" readonly></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta">Nuevo Cant&oacute;n</td>
                    <td><input name="ATxtDesc" type="text" class="SoloStyle_Texto" size="40" maxlength="30"></td>
                </tr>
            </table>
            <br><center>
                <input type="button" name="CmdGrabar" value="Grabar" class="SoloStyle_Boton" onClick="SoloFun_Submit(frmIngreso)"></center>
            <input type="hidden" name="opc" value="G">
        </form>
        <table width="40%" border="0" align="center">
            <tr class="SoloStyle_Etiqueta">
                <td width="80%">Cant&oacute;n</td>
                <td width="20%">Acci&oacute;n</td>
            </tr>
            <?php for ($i=0;$i < count($arrData);$i++) { 
                $clase = "SoloStyle_Texto";

        if ($i%2 == 0 ) $clase = "SoloStyle_Grid"; ?>
            <tr class="<?php echo $clase; ?>">
                <td><?php echo $arrData[$i][2];?></td>
                <td><a href="trn_GrabaCanton.php?id1=<?php echo $arrData[$i][1];?>&id2=<?php echo $arrData[$i][0];?>&ds1=<?php echo $arrData[$i][2];?>&ds2=<?php echo $arrData[$i][3];?>&opc=M">
                        <img src='iconos/soloico_modificar.gif' alt='Modificar' width="23" height="19" border='0' style='cursor:hand'>
                    </a><a href="#" OnClick="Comprobar('trn_GrabaCanton.php?id1=<?php echo $arrData[$i][1];?>&id2=<?php echo $arrData[$i][0];?>&ds1=<?php echo $arrData[$i][2];?>&ds2=<?php echo $arrData[$i][3];?>&opc=E')">
                        <img src='iconos/soloico_eliminar.gif' alt='Borrar Campos' width="23" height="19" border='0' style='cursor:hand'>
                    </a>   </td>
            </tr>
                <?php }

                if(count($arrData) == 0){
                    ?>
            <tr>
                <td colspan="2" class="SoloStyle_Grid" style="text-align: center">No se encontraron cantones registrados para esta provincia</td>
            </tr>
                    <?php }?>

        </table>
    </body>
</html>

<SCRIPT type="text/javascript" src="PHPMailer/fun_generales.js"></SCRIPT>

<script type="text/javascript">

    function Comprobar(pagina){
        //    conf = msgbox("Confirma Eliminar", VBOKCANCEL + VBQUESTION,"SoloPortal")
        var conf = confirm("Confirma Eliminar");
        if (conf)
            window.location.href = pagina

    }

</script>